﻿var isweixin = function () {
    var ua = navigator.userAgent.toLowerCase();
    if (ua.match(/MicroMessenger/i) == "micromessenger") {
        return true;
    } else {
        return false;
    }
}

var getUrlParam = function (name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg); //匹配目标参数
    if (r != null) return unescape(r[2]); return null; //返回参数值
}

var getWidth = function () {
    document.body.clientWidth / 4;
}

function getRandom(n) {
    return Math.floor(Math.random() * n + 1).toString();
}

function PreviewImg(mobile, oid, serverid) {
    location.href = "./PhotoCutPage?m=" + mobile + "&oid=" + oid + "&s=" + serverid;
}

function getNext(o, id, n) {
    if (n != null) {
        if (n < o.length - 1) {
            index = n + 1;
            return o[index];
        }
        else
            return false;
    }
    else {
        for (var i = 0; i < o.length - 1; i++) {
            if (o[i].serverid == id) {
                index = i + 1;
                return o[i + 1];
            }
        }
    }
    return false;
}

function getPrevious(o, id, n) {
    if (n != null) {
        if (n > 0) {
            index = n - 1;
            return o[index];
        }
        else
            return false;
    }
    else {
        for (var i = 1; i < o.length; i++) {
            if (o[i].serverid == id) {
                if (i > 0) {
                    index = i - 1;
                    return o[i - 1];
                }
                else return false;
            }
        }
    }
    return false;
}

function findByServerid(o, id, n) {
    for (var i = 0; i < o.length; i++) {
        if (o[i].serverid == id) {
            index = i;
            return o[i];
        }
    }
}

function getIndexByServerid(o, id) {
    for (var i = 0; i < o.length; i++) {
        if (o[i].serverid == id) {
            index = i;
            return i;
        }
    }
}

function findByIndex(o, n) {
    if (o.length <= n) {
        return false;
    }
    else {
        return o[n];
    }
}